/**   
 * @Title: HemaiCenterAgp.java 
 * @Package com.esun.rabbit2.viewer.mainact 
 * @Description: 合买中心activityGroup 
 * @author: City Jiangsy@500wan.com   
 * @date: 2011-11-25 上午10:46:00  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.viewer.mainact;

import java.util.ArrayList;
import java.util.Hashtable;

import android.app.Activity;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;

import com.esun.config.Config;
import com.esun.network.ConnectionChangeReceiver;
import com.esun.rabbit2.viewer.mainact.titlemenu.TitleMenu;
import com.esun.ui.R;
import com.esun.rabbit2.viewer.mainact.hemaicenteragp.AbsHeMaiActivity;
import com.esun.rabbit2.viewer.mainact.hemaicenteragp.BeidanshengpingfuHemaiListAct;
import com.esun.rabbit2.viewer.mainact.hemaicenteragp.DaletouHemaiListAct;
import com.esun.rabbit2.viewer.mainact.hemaicenteragp.Fucai3DHemaiAct;
import com.esun.rabbit2.viewer.mainact.hemaicenteragp.RenjiuHemaiListAct;
import com.esun.rabbit2.viewer.mainact.hemaicenteragp.ShengfucaiHemaiListAct;
import com.esun.rabbit2.viewer.mainact.hemaicenteragp.ShuangseqiuHemaiAct;
import com.esun.rabbit2.viewer.mainact.hemaicenteragp.SportteryBasketballHemaiAct;
import com.esun.rabbit2.viewer.mainact.hemaicenteragp.SportteryFootballHemaiAct;

/**
 * @ClassName: HemaiCenterAgp
 * @Description: 合买中心activityGroup
 * @author: City Jiangsy@500wan.com
 * @date: 2011-11-25 上午10:46:00
 * 
 */
public class HemaiCenterAgp extends ActivityGroup {
	private LinearLayout linearTop;
	private LinearLayout linearContent;
	private TitleMenu titleMenu;
	private static final String STR_HEMAICENTER = "合买中心";
	private static final String[] STR_HEAD = { "双色球", "福彩3D", "竞彩足球", "竞彩篮球", "大乐透", "胜负彩", "任选9场", "单场竞猜" };
	private static final int[] INT_MENU_BTN_BG = { R.drawable.title_menu_icon_shuangseqiu_style, R.drawable.title_menu_icon_fucaisandi_style, R.drawable.title_menu_icon_sporteryfootball_style,
			R.drawable.title_menu_icon_sporterybasketball_style, R.drawable.title_menu_icon_daletou_style, R.drawable.title_menu_icon_shengfucai_style,
			R.drawable.title_menu_icon_renxuanjiuchang_style, R.drawable.title_menu_icon_danchang_style };

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.hemaicenter_activity_group);
		initView();
	}

	private void initView() {
		linearTop = (LinearLayout) findViewById(R.id.hemaicenteractivitygroup_linear_top);
		titleMenu = new TitleMenu(this, new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				((AbsHeMaiActivity) HemaiCenterAgp.this.getCurrentActivity()).refresh();
			}
		});
		titleMenu.setTitle(STR_HEAD[0] + STR_HEMAICENTER);
		linearContent = (LinearLayout) findViewById(R.id.hemaicenteractivitygroup_linear_content);
		updateTitleMenu();
		swichActivitys(0);

	}

	private void swichActivitys(int position) {
		linearContent.removeAllViews();

		switch (position) {
		case 0:// ShuangseqiuHemaiAct

			linearContent.removeAllViews();
			linearContent.addView(getLocalActivityManager().startActivity("Shuangseqiu", new Intent(this, ShuangseqiuHemaiAct.class)).getDecorView());
			break;

		case 1:// Fucai3DHemaiAct
			linearContent.removeAllViews();
			linearContent.addView(getLocalActivityManager().startActivity("Fucai3D", new Intent(this, Fucai3DHemaiAct.class)).getDecorView());

			break;

		case 2:// SportteryFootballHemaiAct
			linearContent.removeAllViews();
			linearContent.addView(getLocalActivityManager().startActivity("SportteryFootball", new Intent(this, SportteryFootballHemaiAct.class)).getDecorView());
			break;

		case 3:// SportteryBasketBallHemaiAct
			linearContent.removeAllViews();
			linearContent.addView(getLocalActivityManager().startActivity("SportteryBasketball", new Intent(this, SportteryBasketballHemaiAct.class)).getDecorView());
			break;
		case 4:// DaletouHemaiListAct
			linearContent.removeAllViews();
			linearContent.addView(getLocalActivityManager().startActivity("Daletou", new Intent(this, DaletouHemaiListAct.class)).getDecorView());
			break;

		case 5:// ShengfucaiHemaiListAct
			linearContent.removeAllViews();
			linearContent.addView(getLocalActivityManager().startActivity("Shengfucai", new Intent(this, ShengfucaiHemaiListAct.class)).getDecorView());
			break;

		case 6:// RenjiuHemaiListAct
			linearContent.removeAllViews();
			linearContent.addView(getLocalActivityManager().startActivity("Renjiu", new Intent(this, RenjiuHemaiListAct.class)).getDecorView());
			break;

		case 7:// BeidanshengpingfuHemaiListAct
			linearContent.removeAllViews();
			linearContent.addView(getLocalActivityManager().startActivity("Beidanshengpingfu", new Intent(this, BeidanshengpingfuHemaiListAct.class)).getDecorView());
			break;

		default:
			break;
		}

	}

	private void updateTitleMenu() {
		ArrayList<Hashtable<String, Object>> listTitleMenuBtn = new ArrayList<Hashtable<String, Object>>();

		for (int i = 0; i < STR_HEAD.length; i++) {
			final int position = i;
			Hashtable<String, Object> hashtable = new Hashtable<String, Object>();
			hashtable.put(Config.BG_RESOURCE, INT_MENU_BTN_BG[i]);
			hashtable.put(Config.CURRENT_LISTENER, (new OnClickListener() {

				@Override
				public void onClick(View v) {
					swichActivitys(position);
					titleMenu.hideMenu();
					titleMenu.setTitle(STR_HEAD[position] + STR_HEMAICENTER);
				}
			}));
			listTitleMenuBtn.add(hashtable);
		}

		titleMenu.updateListContent(listTitleMenuBtn);
		linearTop.addView(titleMenu.getView());
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.ActivityGroup#onResume()
	 */
	@Override
	protected void onResume() {
		super.onResume();
		this.registerReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver(), ConnectionChangeReceiver.getIntentFilter());
		titleMenu.hideMenu();
	}

	@Override
	protected void onPause() {
		super.onPause();
		this.unregisterReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver());
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Activity parent = getParent();
			if (parent != null) {
				parent.onKeyDown(keyCode, event);
				return true;
			}
		}
		return super.onKeyDown(keyCode, event);
	}

}
